#  NETMAJ - network mahjongg -  Copyright Notice
#      Copyright (C) 1994, 1995, 1996 Koji Suzuki (suz@kt.rim.or.jp)
# 
#   You can redistribute it and/or modify this software under the terms 
#  of the GNU General Public License version 2 as published by
#  the Free Software Foundation.
# 
#   This software is provided 'as-is', without any express or implied
#  warranty.  In no event will the author be held liable for any damages
#  arising from the use of this software.
#  See the gpl.text for more details.
# 
#   If you would like to do something with NETMAJ that this copyright
#  prohibits (such as distributing it with a commercial product,
#  using portions of the source in some other program, etc.), please
#  contact the author (preferably via email).  Arrangements can
#  probably be worked out.
# 
#   Koji Suzuki   : suz@kt.rim.or.jp
#
# $Id: Makefile,v 1.58 1996/11/11 14:43:22 suz Exp $

VERSION=2
REVISION=0
INTERNAL_REVISION=7
ARCFILE=netmaj-$(VERSION).$(REVISION).$(INTERNAL_REVISION).tar.gz

SHELL=/bin/sh
# Install Directory
LIBDIR=/usr/lib/games/netmaj
BINDIR=/usr/games
PERL=/usr/bin/perl

STD_CFLAGS=-I. -Ilib -DNETMAJ_LIB=\"$(LIBDIR)\" 

# for 386BSD,FreeBSD,NetBSD...
#CC=gcc
#OS_CFLAGS= -O -g -DUSE_SGTTY -DUSE_FWOPEN -DUSE_TERMCAP -DHAVE_GETTIMEOFDAY
#RANLIB=ranlib
#LIBS= 
#CURSES= -lcurses -ltermcap
#LDFLAGS =  -Llib 

# for linux
CC=gcc
OS_CFLAGS= -O -DUSE_TERMIOS -DUSE_TERMCAP -DDEF_OPTARG -DHAVE_GETTIMEOFDAY
RANLIB=ranlib
LIBS = 
CURSES= lib/libcurses.a -lncurses
LDFLAGS =  -Llib 

# for nec ews
##CC=/usr/abiccs/bin/cc -ZXNd=5000
#CC=gcc -ansi
#OS_CFLAGS = -O -DSYSV -DSVR4 -DUSE_TERMIOS -DUSE_TERMINFO \
#	-D_ENDWIN_INCURSES  -DHAVE_GETTIMEOFDAY -DDEF_OPTARG
#RANLIB=echo
#LIBS = -lsocket -lnsl
#CURSES= -lcurses -ltermcap
#LDFLAGS =  -Llib 

# for Solaris
#CC=cc
#OS_CFLAGS = -O -DSYSV -DSVR4 -DUSE_TERMIOS -DUSE_TERMINFO -D_ENDWIN_INCURSES \
#	-DUSE_RAND  -DHAVE_GETTIMEOFDAY
#RANLIB=echo
#LIBS = -lsocket -lnsl
#CURSES= -lcurses -ltermcap
#LDFLAGS =  -Llib 

# for nec ews (SVR2)
#CC=cc
#OS_CFLAGS = -O -DSYSV -DSVR4 -DUSE_TERMIO \
#	-DNO_U_LONG -DUSE_TERMCAP -DDEF_OPTARG -DNO_STDLIB -DUSE_WAIT3
#RANLIB=echo
#LIBS =  
#CURSES= -lcurses -ltermcap
#LDFLAGS =  -Llib 

# for SunOS 4.x
#CC=cc 
#OS_CFLAGS= -O -DDEF_OPTARG -DUSE_SGTTY -DUSE_TERMCAP  -DHAVE_GETTIMEOFDAY \
#	-DUSE_WAIT3
#RANLIB=ranlib
#LIBS= -Llib 
#CURSES= -lcurses -ltermcap
#LDFLAGS =

# for HP-UX 9.x
#CC=cc 
#OS_CFLAGS= -O -DSYSV -DUSE_TERMIOS -DUSE_TERMINFO  -DHAVE_GETTIMEOFDAY \
#	-DUSE_WAIT3
#RANLIB=echo
#LIBS= 
#CURSES= -lcurses -ltermcap
#LDFLAGS =  -Llib

# for AIX 3.x
#CC=cc 
#OS_CFLAGS= -O -DSYSV -DOLD_SELECT -DUSE_TERMIOS -DUSE_TERMCAP  \
#	-DHAVE_GETTIMEOFDAY -DUSE_WAIT3
#RANLIB=echo
#LIBS= 
#CURSES= -lcurses -ltermcap
#LDFLAGS =  -Llib

CFLAGS=$(STD_CFLAGS) $(OS_CFLAGS)

STR_DEF=pai_str.o 
STR_NEC=nec_str.o 
STR_ASC=asc_str.o 
OBJS_LIB=ss.o global.o mt.o rv.o hand.o ahand.o result.o log.o cvt.o pf.o \
		game.o analize.o ruledef.o xsleep.o $(STR_DEF)
OBJS_SERVER=server.o
OBJS_CLIENT=client.o cui.o 
OBJS_AUTO  =auto.o 
OBJS_STAND  =stand.o 
OBJS_PLVIEW  = plview.o cui.o 
OBJS_NETMAJ1 =netmaj1.o cui.o 

all: libs server auto client server_kill netmaj1 plview z x
z: proxyserver inputserver proxyclient


libnetmaj.a: $(OBJS_LIB)
	ar ruc libnetmaj.a $(OBJS_LIB)
	$(RANLIB) libnetmaj.a

server_kill: server_kill.o ss.o
	$(CC) -o server_kill server_kill.o ss.o $(LDFLAGS) $(LIBS)

server: $(OBJS_SERVER) libnetmaj.a
	$(CC) -o server $(OBJS_SERVER) libnetmaj.a $(LDFLAGS) $(LIBS)

stand: $(OBJS_STAND) libnetmaj.a
	$(CC) -o stand $(OBJS_STAND) libnetmaj.a $(LDFLAGS) 

netmaj1: $(OBJS_NETMAJ1) libnetmaj.a $(OBJS_COMMON) 
	$(CC) -o netmaj1 $(OBJS_NETMAJ1) libnetmaj.a $(OBJS_COMMON) $(LDFLAGS) \
	 $(LIBS) $(CURSES) 

plview: $(OBJS_PLVIEW) libnetmaj.a
	$(CC) -o plview $(OBJS_PLVIEW) libnetmaj.a $(LDFLAGS) $(CURSES) $(LIBS)

auto: $(OBJS_AUTO) libnetmaj.a
	$(CC) -o auto $(OBJS_AUTO) libnetmaj.a $(LDFLAGS) $(LIBS)

client: $(OBJS_CLIENT) libnetmaj.a
	$(CC) -o client $(OBJS_CLIENT) libnetmaj.a $(LDFLAGS) $(LIBS) $(CURSES) 

proxyclient: proxyclient.o ss.o
	$(CC) -o proxyclient proxyclient.o ss.o $(LDFLAGS) $(LIBS)

inputserver:  inputserver.o ss.o
	$(CC) -o inputserver inputserver.o ss.o $(LDFLAGS) $(LIBS)

proxyserver:  proxyserver.o ss.o
	$(CC) -o proxyserver proxyserver.o ss.o $(LDFLAGS) $(LIBS)

libs:
	(cd lib; make CC="$(CC)" CFLAGS="$(CFLAGS)" RANLIB="$(RANLIB)")

x:
	-if test -d xui; then \
	(cd xui; make CC="$(CC)" OS_CFLAGS="$(OS_CFLAGS)" \
	RANLIB="$(RANLIB)" LIBS="$(LIBS)" LIBDIR="$(LIBDIR) \
	BINDIR="$(BINDIR)" \
	"); fi


netmaj: netmaj.in Makefile
	sed -e "s|LIBDIR|$(LIBDIR)|" < netmaj.in | \
	sed -e "s|BINDIR|$(BINDIR)|" > netmaj
	chmod 755 netmaj

player_info: player_info.in Makefile
	sed -e "s|LIBDIR|$(LIBDIR)|" player_info.in |\
	sed -e "s|PERL|$(PERL)|"  > player_info
	chmod 755 player_info

install: netmaj player_info
	-if test ! -d ${DESTDIR}${BINDIR}; then \
		mkdir ${DESTDIR}${BINDIR}; fi
	-if test ! -d ${DESTDIR}${LIBDIR}; then \
		mkdir ${DESTDIR}${LIBDIR}; fi
	-./server_kill
	cp server client auto server_kill player_info ${DESTDIR}$(LIBDIR)
	cp proxyserver inputserver proxyclient ${DESTDIR}$(LIBDIR)
	cp netmaj.hlp ${DESTDIR}$(LIBDIR)
	cp netmaj netmaj1 plview ${DESTDIR}$(BINDIR)
	-if test -d xui; then \
	(cd xui; make misc/M install CC="$(CC)" OS_CFLAGS="$(OS_CFLAGS)" \
	RANLIB="$(RANLIB)" LIBS="$(LIBS)" LIBDIR="$(LIBDIR)" \
	BINDIR="$(BINDIR)" \
	DESTDIR="$(XUI_DESTDIR)" \
	); fi

install-remote: netmaj server server_kill auto proxyclient
	-if test ! -d ${DESTDIR}${BINDIR}; then \
		mkdir ${DESTDIR}${BINDIR}; fi
	-if test ! -d ${DESTDIR}${LIBDIR}; then \
		mkdir ${DESTDIR}${LIBDIR}; fi
	cp server auto server_kill proxyclient ${DESTDIR}$(LIBDIR)
	cp netmaj ${DESTDIR}$(BINDIR)

install-pf:
	cp *.pf ${DESTDIR}$(LIBDIR)
	-if test -d xui; then \
	(cd xui; make misc/M install-pf CC="$(CC)" OS_CFLAGS="$(OS_CFLAGS)" \
	RANLIB="$(RANLIB)" LIBS="$(LIBS)" LIBDIR="$(LIBDIR)" \
	BINDIR="$(BINDIR)" \
	DESTDIR="$(XUI_DESTDIR)" \
	); fi

clean:
	rm -f *.o core* a.out server auto client server_kill \
		netmaj player_info libnetmaj.a \
		netmaj1 plview proxyserver inputserver proxyclient
	(cd lib; make clean)
	-if test -d xui; then \
	(cd xui; make misc/M clean); fi


tar:
	(cd ..; tar -zcvf netmaj/$(ARCFILE) `cat netmaj/FILES`)

shar: 
	rm -f netmaj.??
	(shar -b -L55 -onetmaj $(ARCFILE))

global.o : global.c pai.h global.h comm.h ss.h
mt.o : mt.c pai.h global.h comm.h ss.h
rv.o : rv.c pai.h global.h ss.h
hand.o : hand.c pai.h global.h ss.h
ahand.o : ahand.c pai.h ahand.h global.h ss.h
result.o : result.c pai.h global.h ruledef.h ss.h
log.o : log.c pai.h global.h ss.h
cvt.o : cvt.c pai.h global.h ss.h
pf.o : pf.c pai.h global.h ss.h
game.o : game.c pai.h global.h ruledef.h ss.h
analize.o : analize.c pai.h ahand.h global.h ss.h
pai_str.o : pai_str.c ss.h
server.o : server.c pai.h global.h ss.h
client.o : client.c pai.h global.h comm.h ss.h
cui.o : cui.c pai.h global.h ss.h
auto.o : auto.c pai.h global.h ss.h
stand.o : stand.c pai.h global.h ss.h
plview.o : plview.c pai.h global.h ss.h
netmaj1.o : netmaj1.c pai.h global.h ss.h
ruledef.o : ruledef.h pai.h global.h ss.h
xsleep.o : xsleep.c global.h ss.h
proxyclient.o : proxyclient.c pai.h global.h comm.h ss.h
proxyserver.o : proxyserver.c pai.h global.h comm.h ss.h
inputserver.o : inputserver.c pai.h global.h comm.h ss.h
ss.o : ss.c ss.h
